
<html>
<head>
 <meta charset="utf-8">
 <title>index</title>
 <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
 <script type="text/javascript" src="jquery-3.1.1.js"></script>
 <script type="application/javascript" src="layui/layui.all.js"></script>
 <link rel="stylesheet" href="layui/css/layui.css">
<style>
.background1{
    background-image:url(img/index2.jpg);
    width:100%;
    height:100%;
}
.action{
    max-width:300px;
    padding-top:110px;
    margin: 0 auto;
    text-align:center;
}
</style>
</head>
<body>
<div class="background1">  
<form class="action" action="index.php" method="post">
<h2 class="form-signin-heading" style="color:blue ; font-size:35px;opacity:0.6;";>LEGISTERED</h2> 
<br/>        
<input type="text" name="username" class="form-control" placeholder="username" 
required autofocus style="opacity:0.5;">
<br/>  
<input type="password" name="password"  class="form-control" placeholder="Password" 
        style="opacity:0.5;">  
<br/> 
<input type="password" name="Repassword" class="form-control" placeholder="RePassword" 
        style="opacity:0.5;"> 
<br/>  
<input type="Submit" name="Submit" class="layui-btn layui-btn-radius layui-btn-normal" value="注册"/> 
<br/>
<a href="login.html"  style="opacity:0.7 ;padding-left:5px;color:black;text-align:center;">不用注册，点此返回！</a> 
<!-- <input a herf="login.html" type="Submit" name="Submit2" class="layui-btn layui-btn-radius layui-btn-normal" value="返回"/>   -->
</form>
</div>
</body>
</html> 
<?php  
    if(isset($_POST["Submit"]) && $_POST["Submit"] == "注册")  
    {  
        $user = $_POST["username"];  
        $psw = $_POST["password"];  
        $psw_repassword = $_POST["Repassword"];  
        if($user == "" || $psw == "" || $psw_repassword == "")  
        {  
            echo "<script>alert('请确认信息完整性！'); history.go(-1);</script>";  
        }  
        else 
        {  
            if($psw == $psw_repassword)  
            {  
                $conn = mysqli_connect("localhost","root","","cqeec",3306); //连接数据库   
                $sql = "select username from user where username = '$_POST[username]'"; //SQL语句  
                $result = mysqli_query($conn,$sql);    //执行SQL语句  
                // $row = mysqli_num_rows($result); //统计执行结果影响的行数  
                if($row = $result->fetch_row())    //如果已经存在该用户  
                {  
                    echo "<script>alert('用户名已存在'); history.go(-1);</script>";  
                }  
                else    //不存在当前注册用户名称  
                {   $conn = mysqli_connect("localhost","root","","cqeec",3306);
                    $sql_insert = "insert into user (username,password,Repassword) values($_POST[username],'$_POST[password]','$_POST[Repassword]')";  
                    $res_insert = mysqli_query($conn,$sql_insert);  
                    // $num_insert = mysql_num_rows($res_insert);  
                    if($res_insert)  
                    {  
                        // echo "<script>alert('注册成功！');</script>"; 
                        // header ("location:login.html"); 
                        echo "<script> alert('注册成功！');parent.location.href='login.html'; </script>"; 
                    }  
                  else 
                    {  
                       echo "<script>alert('系统繁忙，请稍候！'); history.go(-1);</script>";  
                    }  
                }  
            }  
            else 
            { 
                echo "<script>alert('密码不一致！'); history.go(-1);</script>";  
            }  
        }  
    }  
    else 
{
    // echo "<script>alert('不一致！'); history.go(-1);</script>";
} 
?>